// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class MF_TEST_BATT_DETAIL_MFN_M10 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("5 OM5",5)]
  	    [HL7Field(HL7Version.v23, 5, HL7Repeat.False, HL7Required.True,"OM5")]
	    public OM5 OM5 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("8 OM4",8)]
  	    [HL7Field(HL7Version.v23, 8, HL7Repeat.True, HL7Required.False,"OM4")]
	    public OM4[] OM4 {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			OM5 = PopSegmentParseAndCheckRequired<OM5>(availableData, options, "OM5");
			OM4 = PopSegmentParseAndCheckRequiredArray<OM4>(availableData, options, "OM4");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isOM5 = availableData.StartsWith("OM5", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OM5", options.Version) || isOM5) {
				return isOM5;
			}
			bool isOM4 = availableData.StartsWith("OM4", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OM4", options.Version) || isOM4) {
				return isOM4;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "MF_TEST_BATT_DETAIL";
			}
        }

        static MF_TEST_BATT_DETAIL_MFN_M10() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(MF_TEST_BATT_DETAIL_MFN_M10));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (OM5 != null) {
			string segmentValue = OM5.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (OM4 != null && OM4.Length > 0) {
			for (int i = 0; i < OM4.Length; i++) {
				string segmentValue = OM4[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

